package org.lex.swing.widgets;

import java.net.NetworkInterface;

import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;

import org.lex.swing.ContainerFactory;
import org.lex.swing.Swings;


public class NetworkInterfacesPane extends JSplitPane {
	private NetworkInterfaceTree tree = null;
	private NetworkInterfaceTable table = null;

	public static void main(String[] args) {
		Swings.setUseBoldMetalFont(false);
		Swings.show(new NetworkInterfacesPane(), false);
	}

	public NetworkInterfacesPane() {
		super();
		initialize();
	}

	private void initialize() {
		// initialize children
		tree = new NetworkInterfaceTree();
		table = new NetworkInterfaceTable();
		tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
			public void valueChanged(TreeSelectionEvent e) {
				NetworkInterface ni = tree.getSelectedNetworkInterface();
				if (null != ni)
					table.setNetworkInterface(ni);
			}
		});
		// wrap children in scrollpane, and add them to me
		ContainerFactory.setSplitPaneBorderless(this);
		this.setDividerSize(5);
		this.setResizeWeight(0.35D);
		this.setLeftComponent(new JScrollPane(tree));
		this.setRightComponent(new JScrollPane(table));
	}
}
